<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="查询日期" prop="dealDate">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.startDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="-----" prop="dealDate">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.endDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div>
      <el-radio-group v-model="queryParams.operationType" @change="handleQuery">
        <el-radio-button label="1" >收入明细</el-radio-button>
        <el-radio-button label="2">支出明细</el-radio-button>
      </el-radio-group>
    </div><br/>

    <div>
      <span style="font-weight: bold">金额总计：{{dealPerDayTotalVO.totalSum}}元</span><br/><br/>
      <span>押金(总计):{{dealPerDayTotalVO.depositSum}}元</span>
      <span style="margin: 30px">租金(总计):{{dealPerDayTotalVO.rentSum}}元</span>&nbsp;
      <span style="margin: 30px">电费(总计):{{dealPerDayTotalVO.electricityFeeSum}}元</span>&nbsp;
      <span style="margin: 30px">水费(总计):{{dealPerDayTotalVO.waterFeeSum}}元</span>&nbsp;
      <span style="margin: 30px">宽带费(总计):{{dealPerDayTotalVO.netFeeSum}}元</span>&nbsp;
      <span style="margin: 30px">燃气费(总计):{{dealPerDayTotalVO.gasFeeSum}}元</span>&nbsp;
      <span style="margin: 30px">有线电视费(总计):{{dealPerDayTotalVO.cableFeeSum}}元</span>&nbsp;
      <span style="margin: 30px">其他(总计):{{dealPerDayTotalVO.otherFeeSum}}</span>
    </div><br/>


    <el-table v-loading="loading" :data="dayList" >
      <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总计(元)" align="center" prop="total" />
      <el-table-column label="押金(元)" align="center" prop="deposit" />
      <el-table-column label="租金(元)" align="center" prop="rent" />
      <el-table-column label="电费(元)" align="center" prop="electricityFee" />
      <el-table-column label="水费(元)" align="center" prop="waterFee" />
      <el-table-column label="宽带费(元)" align="center" prop="netFee" />
      <el-table-column label="燃气费(元)" align="center" prop="gasFee" />
      <el-table-column label="有线电视费(元)" align="center" prop="cableFee" />
      <el-table-column label="其他(元)" align="center" prop="otherFee" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="checkDetails(scope.row)"
            v-hasPermi="['system:day:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!--    营业报表（收入或支出）明细对话框-->
    <el-dialog
      title="查看明细"
      :visible.sync="dialogVisible"
      width="50%">
      <template>
        <span style="font-weight: bold" >交易时间：{{dealPerDayDetailParams.dealDate}}</span><br/><br/>
        <div v-if="queryParams.operationType==1">
          <span style="font-weight: bold">收入金额总计(元):{{receiptPlanTotal}}元</span>
        </div>
        <div v-else>
          <span style="margin: 10px;font-weight: bold">支出金额总计(元):{{paymentPlanTotal.allPaySum}}元</span>
          <span style="margin: 10px;font-weight: bold">快捷通(元):{{paymentPlanTotal.kjtSum}}元</span>
          <span style="margin: 10px;font-weight: bold">支付宝平台总和(元):{{paymentPlanTotal.zfbSum}}元</span>
          <span style="margin: 10px;font-weight: bold">微信平台总和(元):{{paymentPlanTotal.wxSum}}元</span>
          <span style="margin: 10px;font-weight: bold">现金合计(元):{{paymentPlanTotal.xjSum}}元</span>
          <span style="margin: 10px;font-weight: bold">银行转账合计(元):{{paymentPlanTotal.yhzzSum}}元</span>
          <span style="margin: 10px;font-weight: bold">pos机合计(元):{{paymentPlanTotal.posSum}}元</span>
          <span style="margin: 10px;font-weight: bold">其他合计(元):{{paymentPlanTotal.otherSum}}元</span>
        </div>
      </template>
      <el-table
        :data="dealPerDayDetailVOList"
        style="width: 100%">
      <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房源名称" align="center" prop="roomName" />
      <el-table-column label="租客姓名" align="center" prop="tenantName" />
      <el-table-column label="租客电话" align="center" prop="tenantPhone" />
      <el-table-column label="费用类型" align="center" prop="itemType">
        <template slot-scope="scope">
          <span v-if="scope.row.itemType==1">水费</span>
          <span v-else-if="scope.row.itemType==2">电费</span>
          <span v-else-if="scope.row.itemType==3">煤/燃气费</span>
          <span v-else-if="scope.row.itemType==80">租金</span>
          <span v-else-if="scope.row.itemType==81">押金</span>
          <span v-else-if="scope.row.itemType==90">解约结算</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>
      <el-table-column label="收支状态" align="center" prop="dealDesc" />
      <el-table-column label="金额" align="center" prop="realPaymentAmount" />
      <el-table-column label="支付方式" align="center" prop="payMethod">
        <template slot-scope="scope">
          <span v-if="scope.row.payMethod==1">快捷</span>
          <span v-else-if="scope.row.payMethod==2">支付宝</span>
          <span v-else-if="scope.row.payMethod==3">微信</span>
          <span v-else-if="scope.row.payMethod==4">现金</span>
          <span v-else-if="scope.row.payMethod==5">银行卡转账</span>
          <span v-else-if="scope.row.payMethod==6">POS集刷卡</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>
      </el-table>
      <pagination
        v-show="dealPerDayDetailPageTotal>0"
        :total="dealPerDayDetailPageTotal"
        :page.sync="dealPerDayDetailParams.pageNum"
        :limit.sync="dealPerDayDetailParams.pageSize"
        @pagination="toGetReceiptPlanList"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listDay, delDay, addDay, updateDay ,getReceiptPlanList,getPaymentPlanList} from "@/api/financing/day";

export default {
  name: "Day",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //营业报表（收入或支出）详情总条数
      dealPerDayDetailPageTotal: 0,
      // 【营业报表】表格数据
      dayList: [],
      //营业报表（收入或支出）详情集合
      dealPerDayDetailVOList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dealDate: null,
        operationType: 1,
        startDate:null,
        endDate:null,
      },
      //营业报表（收入或支出）详情查询参数
      dealPerDayDetailParams:{
        pageNum: 1,
        pageSize: 5,
        dealDate: null,
      },
      //营业报表的总计
      dealPerDayTotalVO:{},
      //收入明细的对话框
      dialogVisible:false,
      //某天收入明细的金额总计
      receiptPlanTotal:null,
      //某天支出明细顶部总计金额信息
      paymentPlanTotal:{},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listDay(this.queryParams).then(response => {
        this.dayList = response.data.list.rows;
        this.total = response.data.list.total;
        this.dealPerDayTotalVO=response.data.total;
        this.loading = false;
      });
    },
    /** 查看详情 */
    checkDetails(row) {
      this.dealPerDayDetailParams.dealDate=row.dealDate;
      this.dealPerDayDetailParams.pageNum=1;
      //查询收入明细
      if (this.queryParams.operationType == 1) {
        this.toGetReceiptPlanList();
      }else {
        console.log("查询支出");
        this.toGetPaymentPlanList();
      }
    },
    //查询收入明细
    toGetReceiptPlanList() {
      getReceiptPlanList(this.dealPerDayDetailParams).then(response=>{
        this.dialogVisible=true;
        this.dealPerDayDetailVOList=response.data.receiptPlanVOList.rows;
        this.dealPerDayDetailPageTotal=response.data.receiptPlanVOList.total;
        this.receiptPlanTotal=response.data.totalSum;
      })
    },
    //查询支出明细
    toGetPaymentPlanList() {
      getPaymentPlanList(this.dealPerDayDetailParams).then(response=>{
        this.dialogVisible=true;
        this.dealPerDayDetailVOList=response.data.paymentPlanList.rows;
        this.dealPerDayDetailPageTotal=response.data.paymentPlanList.total;
        this.paymentPlanTotal=response.data.paymentPlanTotalVO;
        console.log("response",response);
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.startDate=null;
      this.queryParams.endDate=null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDay(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDay(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDay(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/day/export', {
        ...this.queryParams
      }, `system_day.xlsx`)
    }
  }
};
</script>
